/**
 * 
 */
package com.ekingstar.hedss.action;

import java.util.List;

import org.apache.struts2.config.Action;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletActionRedirectResult;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.conversion.annotations.Conversion;
import com.opensymphony.xwork2.util.Element;
import com.ekingstar.framework.app.ApplicationParameter;
import com.ekingstar.framework.domain.User;
import com.ekingstar.framework.security.UserUtil;
import com.ekingstar.framework.util.Page;
import com.ekingstar.hedss.domain.HedssZlfj;
import com.ekingstar.hedss.domain.HedssZllb;
import com.ekingstar.hedss.domain.HedssZlxx;
import com.ekingstar.hedss.service.IHedssService;

@SuppressWarnings("serial")
@Action(name="documentation",namespace="/documentation")
@Results( {
	@Result(name = "listzlxxview", value = "/pages/documentation/zlxx-listview.jsp"),	
	@Result(name = "viewonlyzlxx", value = "/pages/documentation/zlxx-viewonly.jsp"),
	@Result(name = "listzlxx", value = "/pages/documentation/zlxx-list.jsp"),
	@Result(name = "listzllb", value = "/pages/documentation/zllb-list.jsp"),
	@Result(name = "viewzlxx", value = "/pages/documentation/zlxx-view.jsp"),
	@Result(name = "viewzllb", value = "/pages/documentation/zllb-view.jsp"),
	@Result(name="delzllbsuccess",value="documentation.action",type=ServletActionRedirectResult.class),
	@Result(name="delzlxxsuccess",value="documentation!listZlxxPage.action",type=ServletActionRedirectResult.class,params={"searchzlxx.TZllb.id","${zlxx.TZllb.id}"}),
	@Result(name="delzlfjsuccess",value="documentation!viewZlxx.action",type=ServletActionRedirectResult.class,params={"id","${zlxx.id}","searchzlxx.TZllb.id","${zlxx.TZllb.id}"})})
@Conversion
public class DocumentationAction extends ActionSupport{
	
	
	private IHedssService hedssService;
	private HedssZllb zllb;
	private HedssZlxx zlxx;
	private HedssZlfj zlfj;
	private HedssZllb searchzllb;
	private HedssZlxx searchzlxx;
	private List<HedssZllb> zllbList;
	private List<HedssZlxx> zlxxList;
	@Element(HedssZlfj.class)
	private List<HedssZlfj> zlfjList;
	private List haszlxx;
	private List haszlfj;
	private Page page;
	private int pageNo = 1;
	private int pageSize = ApplicationParameter.INSTANCE.getPageSize();
		
	private String id;
	
	public String execute(){
		boolean logged = UserUtil.isLogged();
		if (!logged ){
			return "nologin";
		}
		
		this.page = hedssService.getZllblist(searchzllb,pageNo, pageSize);
		return "listzllb";		
	}
	
	public String viewZllb(){
		this.zllb = hedssService.viewZllb(id);
		this.haszlxx = hedssService.getZlxxByZllbId(this.zllb.getId());
		return "viewzllb";
	}
	
	public String deleteZllb(){
		boolean logged = UserUtil.isLogged();
		if (!logged ){
			return "nologin";
		}
		
		if(zllb!=null&&zllb.getId()!=null&&!zllb.getId().trim().equals(""))
			hedssService.deleteZllb(zllb.getId());
		
		return "delzllbsuccess";
	}
	
	public String listZlxxPage(){
		if(zllbList==null)
			zllbList =(hedssService.getZllblist(new HedssZllb(), 0, -1)).getRes();
		
		this.page = hedssService.getZlxxlist(searchzlxx,pageNo, pageSize);		
		return "listzlxx";
	}
	
	public String listZlxxPageView(){
		boolean logged = UserUtil.isLogged();
		if (!logged ){
			return "nologin";
		}
		
		if(zllbList==null)
			zllbList =(hedssService.getZllblist(new HedssZllb(), 0, -1)).getRes();
		
		this.page = hedssService.getZlxxlist(searchzlxx,pageNo, pageSize);		
		return "listzlxxview";
	}
	
	public String viewZlxx(){
		this.zlxx = hedssService.viewZlxx(id);
		this.haszlfj = hedssService.getZlfjByZlxxId(this.zlxx.getId());
		return "viewzlxx";
	}
		
	public String viewonlyZlxx(){
		this.zlxx = hedssService.viewZlxx(id);
		this.haszlfj = hedssService.getZlfjByZlxxId(this.zlxx.getId());
		return "viewonlyzlxx";
	}
		
	public String deleteZlxx(){
		boolean logged = UserUtil.isLogged();
		if (!logged ){
			return "nologin";
		}
		
		if(zlxx!=null&&zlxx.getId()!=null&&!zlxx.getId().trim().equals("")){
			zlxx=hedssService.getZlxx(zlxx.getId());
			hedssService.deleteZlxx(zlxx.getId());
		}
		
		return "delzlxxsuccess";
	}
	
	public String deleteZlfj(){
		boolean logged = UserUtil.isLogged();
		if (!logged ){
			return "nologin";
		}
				
		if(zlfj!=null&&zlfj.getId()!=null&&!zlfj.getId().trim().equals("")){
			zlfj=hedssService.getZlfj(zlfj.getId());
			zlxx=hedssService.getZlxx(zlfj.getTZlxx().getId());
			hedssService.deleteZlfj(zlfj.getId());
		}
		return "delzlfjsuccess";
	}
	
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String tree(){
		
		return "tree";
	}		

	public List getHaszlfj() {
		return haszlfj;
	}

	public void setHaszlfj(List haszlfj) {
		this.haszlfj = haszlfj;
	}

	public List getHaszlxx() {
		return haszlxx;
	}

	public void setHaszlxx(List haszlxx) {
		this.haszlxx = haszlxx;
	}

	public IHedssService getHedssService() {
		return hedssService;
	}

	public void setHedssService(IHedssService hedssService) {
		this.hedssService = hedssService;
	}

	public List<HedssZlfj> getZlfjList() {
		return zlfjList;
	}

	public void setZlfjList(List<HedssZlfj> zlfjList) {
		this.zlfjList = zlfjList;
	}

	public HedssZllb getZllb() {
		return zllb;
	}

	public void setZllb(HedssZllb zllb) {
		this.zllb = zllb;
	}

	public HedssZlxx getZlxx() {
		return zlxx;
	}

	public void setZlxx(HedssZlxx zlxx) {
		this.zlxx = zlxx;
	}	
	
	public HedssZlfj getZlfj() {
		return zlfj;
	}

	public void setZlfj(HedssZlfj zlfj) {
		this.zlfj = zlfj;
	}

	public HedssZllb getSearchzllb() {
		return searchzllb;
	}

	public void setSearchzllb(HedssZllb searchzllb) {
		this.searchzllb = searchzllb;
	}

	public HedssZlxx getSearchzlxx() {
		return searchzlxx;
	}

	public void setSearchzlxx(HedssZlxx searchzlxx) {
		this.searchzlxx = searchzlxx;
	}

	public List<HedssZlxx> getZlxxList() {
		return zlxxList;
	}

	public void setZlxxList(List<HedssZlxx> zlxxList) {
		this.zlxxList = zlxxList;
	}

	public List<HedssZllb> getZllbList() {
		return zllbList;
	}

	public void setZllbList(List<HedssZllb> zllbList) {
		this.zllbList = zllbList;
	}
	

}
